# -*- coding:utf-8 -*-
import pyttsx3
import threading


speed = 50


def init_engine():
	engine=pyttsx3.init()
	print('---准备开始语音播报...---')

	# 设置发音速率，默认值为200
	rate = engine.getProperty('rate')
	engine.setProperty('rate', rate + speed )
	# 设置发音大小，范围为 0 -1.0
	volume = engine.getProperty('volume')
	engine.setProperty('volume', 1.0)
	# 设置默认的声音：voices[0].id代表男生（可以中文），voices[1].id代表女生
	voices = engine.getProperty('voices')
	engine.setProperty('voice', voices[0].id)
	return engine


def get_txt():
	with open("input.txt", 'r', encoding='utf-8') as f:
		s = f.read()
		print(s)
		return s

def read(engine, s):
	engine.say(s) 
	engine.runAndWait()

if __name__ == "__main__":
	engine = init_engine()
	s = get_txt()
	read(engine, s)
	while True:
		line  = input("按任意键继续从txt中读 x")
		if line == "x":
			break
		s = get_txt()
		read(engine, s)
	print("已经结束----")